import os

import pandas
import pandas as pd

class DataOperation:
    def __init__(self, file_path):

        _, extension = os.path.split(file_path)
        if extension in ('.txt', '.csv', '.tsv'):
            self.data = pd.read_csv(file_path)
        elif extension in ('.xlsx', '.xls'):
            self.data = pd.read_excel(file_path, sheet_name=0)
        else:
            print('没有此路径')


    # 查看前几行,默认查看前5行
    def get_head(self):
        return self.data.head(6)

    # 查看数据的形状, 返回(行列)
    def get_shape(self):
        return self.data.shape

    # 查看字段名
    def get_columns(self):
       return self.data.columns

    # 查看索引
    def index(self):
        return self.data.index


if __name__ == '__main__':
    project_path = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
    path = os.path.join(project_path, 'taxt.xlsx')
    data = DataOperation(path)
